AWS S3 : Prevent Hotlinking policy
Problem :
Hosting a lot of photos or video files on AWS S3? Don't want other websites to link to your content or use your S3 as a free loader?
Solution :
Add new bucket policy to prevent hot linking. Go to the properties of the S3 bucket you want to prevent hot linking policy and click on the Add Bucket Policy button.
A modal box will appear and enter this policy :
{
"Version": "2008-10-17",
"Id": "preventHotLinking",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-s3-bucket/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"http://yourwebsitename.com/*",
"http://www.yourwebsitename.com/*"
]
}
}
}
]
}
NOTE : Change your-s3-bucket and yourwebsitename.com to yours.
Reference :
https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
See also : WARNING: UNPROTECTED PRIVATE KEY FILE! error message
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+9.5k Golang : Create unique title slugs example
+5.3k JavaScript/JQuery : Redirect page examples
+5.8k List of Golang XML tutorials
+7.4k Golang : Not able to grep log.Println() output
+19.9k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+9.6k Golang : Changing a RGBA image number of channels with OpenCV
+8.7k Golang : Set or add headers for many or different handlers
+6.4k PHP : Proper way to get UTF-8 character or string length
+34.1k Golang : Proper way to set function argument default value
+22.3k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+16.5k Golang : How to implement two-factor authentication?
+5.8k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag